Action hook 'wp_ajax_{$action}'

in WP Core File wp-admin/admin-ajax.php at line 192

View Source

wp_ajax_{$action}

Action Hook
Description
Fires authenticated Ajax actions for logged-in users. The dynamic portion of the hook name, `$action`, refers to the name of the Ajax action callback being fired.

Hook Information

File Location wp-admin/admin-ajax.php View on GitHub
Hook Type Action
Line Number 192

Hook Parameters

This hook doesn't accept any parameters.

Usage Examples

Basic Usage
<?php
// Hook into wp_ajax_{$action}
add_action('wp_ajax_{$action}', 'my_custom_function');

function my_custom_function() {
    // Your custom code here
}

Source Code Context

wp-admin/admin-ajax.php:192 - How this hook is used in WordPress core
<?php
 187  	 * The dynamic portion of the hook name, `$action`, refers
 188  	 * to the name of the Ajax action callback being fired.
 189  	 *
 190  	 * @since 2.1.0
 191  	 */
 192  	do_action( "wp_ajax_{$action}" );
 193  } else {
 194  	// If no action is registered, return a Bad Request response.
 195  	if ( ! has_action( "wp_ajax_nopriv_{$action}" ) ) {
 196  		wp_die( '0', 400 );
 197  	}

PHP Documentation

<?php
/**
	 * Fires authenticated Ajax actions for logged-in users.
	 *
	 * The dynamic portion of the hook name, `$action`, refers
	 * to the name of the Ajax action callback being fired.
	 *
	 * @since 2.1.0
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 0
  • File: wp-admin/admin-ajax.php
Related Hooks

Related hooks will be displayed here in future updates.